package gui;

import application.Resolution;
import application.StatutLabel;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JLabel;
import javax.swing.plaf.basic.BasicBorders;

/**
 *
 * @author Alexis
 */
public class LabelInterface extends JLabel {
    private Resolution resolution;
    private StatutLabel statutLabel;
    private int statMax;
    private double ratioRemplissage;
    
    public LabelInterface (StatutLabel statut, Resolution res) {
        statutLabel = statut;
        resolution = res;
        this.statMax = 10;
        ratioRemplissage = 1.0;
        
        setBorder(new BasicBorders.ButtonBorder(Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE));
    }
    
    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2d;
        Font font;
        FontMetrics fontMetrics;
        int largeurTexte, hauteurTexte, fontSize = 30;
        String texte = "";

        if (resolution == Resolution.R1920x1080) {
            fontSize = 45;
        } else if (resolution == Resolution.R1280x1024) {
            fontSize = 30;
        } else if (resolution == Resolution.R800x600) {
            fontSize = 20;
        }

        g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        font = new Font("Imprint MT Shadow", Font.PLAIN, fontSize);
        fontMetrics = g2d.getFontMetrics(font);
        g2d.setFont(font);
        
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, getWidth(), getHeight());
        
        if (statutLabel == StatutLabel.VIE) {
            texte = statutLabel.toString();
            g2d.setColor(new Color(178, 34, 34));
        } else if (statutLabel == StatutLabel.ESSENCE) {
            texte = statutLabel.toString();
            g2d.setColor(new Color(139, 69, 19));
        } else if (statutLabel == StatutLabel.NOM) {
            texte = getText();
            g2d.setColor(new Color(139, 69, 19));
        } else if (statutLabel == StatutLabel.AMMO) {
            texte = statutLabel.toString();
            g2d.setColor(Color.DARK_GRAY);
        }
        
        g2d.fillRect(0, 0, (int) (getWidth() * ratioRemplissage), getHeight());
        
        largeurTexte = fontMetrics.stringWidth(texte);
        hauteurTexte = fontMetrics.getHeight();
        
        g2d.setColor(Color.WHITE);
        g2d.drawString(texte, getWidth() / 2 - largeurTexte / 2, getHeight() / 2 + hauteurTexte / 4);
    }
    
    public void setResolution(Resolution newResolution) {
        resolution = newResolution;
    }
    
    public void setRatioRemplissage(int statActuel) {
        ratioRemplissage = (double) statActuel / (double) statMax;
    }
    
    public void setStatMax(int newStatMax) {
        statMax = newStatMax;
    }
}
